Static .Net library methods can be called from PowerShell by encapsulating the full class name in third bracket and then calling the method using ::
#calling Path.GetFileName() C:\> [System.IO.Path]::GetFileName('C:\Windows\explorer.exe') explorer.exe
Static methods can be called from the class itself, but calling non-static methods requires an instance of the .Net class (an object).
For example, the AddHours method cannot be called from the System.DateTime class itself. It requires an instance of the class:
PS E:\Data\samples> [System.DateTime]::AddHours(15) Method invocation failed because [System.DateTime] does not contain a method named 'AddHours'. At line:1 char:1 + [System.DateTime]::AddHours(15) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
In this case, we first create an object, Then, we can use methods of that object, even methods which cannot be called directly from the System.DateTime class, like the AddHours method:
C:\> $Object = [System.DateTime]::Now C:\> $Object.AddHours(15)
we have to first examine .NET Framework assemblies and see whether they are loaded. When it comes to seeing whether a particular .NET Framework assembly is loaded, it is easiest to use the Add-Type Windows PowerShell cmdlet, and try to load the assembly
PS C:\> Add-Type -AssemblyName System.ServiceProcess PS C:\> Add-Type -assembly Microsoft.VisualBasic PS C:\> [Microsoft.VisualBasic.Interaction]::MsgBox("Do you agree?", "YesNoCancel,Question", "Question")
To check whether assembly loaded correctly or not, put the .NET Framework class name (together with the .NET Framework namespace the class resides in) into a pair of square brackets.
PS C:\> [System.ServiceProcess.ServiceController]